package com.newlink.building.secret.adapter

import android.widget.CheckBox
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.newlink.building.secret.R
import com.newlink.building.secret.bean.Module_Secret_CheckBean

/**
 * Created by xiaodong on 2022/8/30.
 */
class Module_Secret_AreaSelectionAdapter(data: MutableList<Module_Secret_CheckBean>) :
    BaseQuickAdapter<Module_Secret_CheckBean, BaseViewHolder>(R.layout.item_area_selection, data) {
    init {
        addChildClickViewIds(R.id.area_container)
    }

    override fun convert(holder: BaseViewHolder, item: Module_Secret_CheckBean) {
        holder.setText(R.id.tv_area, item.name)
        val checkBox = holder.getView<CheckBox>(R.id.cb_select)
        val textView = holder.getView<TextView>(R.id.tv_area)
        when (item.type) {
            0 -> {
                checkBox.setBackgroundResource(R.drawable.common_checkbox_square)
            }

            1 -> {
                checkBox.setBackgroundResource(R.drawable.common_checkbox_circle)
                textView.setTextColor(
                    if (item.isChecked) context.getColor(R.color.colorPrimary) else context.getColor(
                        R.color.color_3030300
                    )
                )
            }
        }
        checkBox.isChecked = item.isChecked
//        checkBox.setOnCheckedChangeListener { _, isChecked ->
//            item.isChecked = isChecked
//        }
    }
}